package com.admin.business.background.venusOaOutsourcingCostCycle;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 财务外包费用周期表
 * @create: 2023-11-03 13:45:33
 **/
@Service("venusOaOutsourcingCostCycleService")
@Slf4j
public class VenusOaOutsourcingCostCycleService{

    @Resource
    VenusOaOutsourcingCostCycleDao venusOaOutsourcingCostCycleDao;

    /**
     * 添加财务外包费用周期表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:缴费周期id(财务外包费用id)
     *                   - pay_begin_time:缴费开始时间
     *                   - pay_end_time:缴费结束时间
     *                   - current_expenses:本期费用
     *                   - charging_time:收费提示时间:每期收费，到期前几天提示！
     *                   - payment_status:缴费状态:1、已缴，2、未交
     *                   - iscancel:是否免支付：0、正常，1、免支付
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return addVenusOaOutsourcingCostCycle(CDO cdoRequest) {
        venusOaOutsourcingCostCycleDao.addVenusOaOutsourcingCostCycle(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新财务外包费用周期表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:缴费周期id(财务外包费用id)
     *                   - pay_begin_time:缴费开始时间
     *                   - pay_end_time:缴费结束时间
     *                   - current_expenses:本期费用
     *                   - charging_time:收费提示时间:每期收费，到期前几天提示！
     *                   - payment_status:缴费状态:1、已缴，2、未交
     *                   - iscancel:是否免支付：0、正常，1、免支付
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return updateVenusOaOutsourcingCostCycleById(CDO cdoRequest) {
        venusOaOutsourcingCostCycleDao.updateVenusOaOutsourcingCostCycleById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除财务外包费用周期表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return deleteVenusOaOutsourcingCostCycleById(CDO cdoRequest){
        int count = venusOaOutsourcingCostCycleDao.deleteVenusOaOutsourcingCostCycleById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除财务外包费用周期表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return deleteVenusOaOutsourcingCostCycle(CDO cdoRequest) {
        int count = venusOaOutsourcingCostCycleDao.deleteVenusOaOutsourcingCostCycle(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取财务外包费用周期表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return getVenusOaOutsourcingCostCycleById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaOutsourcingCostCycleDao.getVenusOaOutsourcingCostCycleById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取财务外包费用周期表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return getVenusOaOutsourcingCostCycleListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaOutsourcingCostCycleDao.getVenusOaOutsourcingCostCycleListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaOutsourcingCostCycleDao.getVenusOaOutsourcingCostCycleCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取财务外包费用周期表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 13:45:33
     */
    @OpenApi
    public Return getVenusOaOutsourcingCostCycleListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaOutsourcingCostCycleDao.getVenusOaOutsourcingCostCycleListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaOutsourcingCostCycleDao.getVenusOaOutsourcingCostCycleCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
